/*
 * Created on 2005-maj-03
 * by Persson
 */
package org.leviatan.common.keyutils;
/**
 * @author Persson
 * @version 0.4
 */
public class KeyGenerator {
	
	private static long lastGeneratedId;
	private static long current;
	
    public static synchronized String generateUniqueKeyAsString() {
        return Long.toString( generateUniqueKey() );
    }
    
    public static synchronized long generateUniqueKey() {
    	long current = System.currentTimeMillis();
    	while (current <= lastGeneratedId) {
    		current++;
    	}
    	lastGeneratedId = current;
    	return current;
    }
	
	public static synchronized Long generateUniqueKeyAsLong() {
		return Long.valueOf( generateUniqueKey() );
	}
	
}
